

// import 'babel-polyfill'
import Vue from 'vue'
// import Es6Promise from 'es6-promise'
// Es6Promise.polyfill()
import App from './App'
import router from './router'
import axios from 'axios'
import $ from 'jquery'
import Vuex from 'vuex'
import "./assets/js/common.js"
// import WXConfig from './assets/js/wx.jsapi'//微信分享
// import wx from 'weixin-js-sdk'
import Tool from './assets/js/Tool'
import LyTab from 'ly-tab'

import Base64 from  './assets/js/base64'


// 引入js
import "./assets/css/layer.css"
import "./assets/css/common.css"
// import "./assets/css/load.css"
// import "./assets/css/idangerous.swiper.css"
import "./assets/css/tis-ui-1.1-perty.css"
import "./assets/fonts/fontawesome-webfont.woff2"
import "./assets/css/tis-ui-1.1-perty.css"
// import "./assets/css/font-awesome.css"
// import "./assets/css/tis-ui-1.1-perty.css"



//复制链接
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
import Mint from 'mint-ui';
import 'mint-ui/lib/style.css';
//登录方法
import deng from './assets/j/deng'
Vue.use(deng);


import loginsuccess from './assets/j/loginsuccess'
Vue.use(loginsuccess);

//微信分享
import sdk from './assets/j/sdk'


import Bridge  from './assets/j/bridge.js'
Vue.prototype.$bridge = Bridge 

// axios
import request from './assets/j/wxRequest'
Vue.prototype.request = request;



import sharelogin from './assets/j/share'
// Vue.prototype.sharelogin = sharelogin;
Vue.use(sharelogin);


//vant
import Vant from 'vant';
import 'vant/lib/index.css';

Vue.use(Vant);


// 下拉加载
import VueScroller  from 'vue-scroller'
Vue.use(VueScroller)

//标题
import VueWechatTitle from 'vue-wechat-title';
import { Loadmore } from 'mint-ui';
// import Cube from 'cube-ui'
//
// Vue.use(Cube)
Vue.component(Loadmore.name, Loadmore);

Vue.config.productionTip = false
Vue.prototype.axios = axios

// Vue.prototype.WXConfig =WXConfig
Vue.prototype.Tool = Tool;
Vue.prototype.sdk = sdk;
Vue.use(Vuex);
// Vue.use(Mui);
Vue.use(Mint);
Vue.use(LyTab);
Vue.use(VueWechatTitle);
// Vue.use(ElementUI);

var token = localStorage.getItem('token');
if(token){
axios.defaults.headers.common['token'] = token;
}else{
axios.defaults.headers.common['token'] = '';
}
axios.defaults.headers.common['version'] = 'v1';
axios.defaults.headers.common['fromsource'] = 1;
axios.defaults.headers.common['device'] = 'H5';

const Module = {
  state: {
	// 正式(赛思医考帮) 
	url:'https://n.qikeya.com/saisi/public/index.php/api/',
	
	// url:'https://www.ssykb.cn/api/',
	
	
    linkurltap:'://www.ssykb.cn',
	

	// 图片(赛思医考帮测试，正式)
	 img:'https://saisi.oss-cn-beijing.aliyuncs.com',


	// 咨询手机号
	phoneurl:'15639255665',

	// 默认头像
	avatarimg:'https://qikeya.oss-cn-beijing.aliyuncs.com/Uploads/20190425/header_icon.png',
	// avatarimg:'http://zhibo.qikeya.com/Public/img/avatar_0.png',

	// 来源
	fromsource:1,
	vernew:'当前版本：1.0.1',
	// 分享描述
	desc:'我在赛思医考帮学习如何有效备战医学考试，赶快来学习吧！',
	// 默认分享图片
	imgdesc:'https://saisi.oss-cn-beijing.aliyuncs.com/Uploads/image/32.jpg',
	
	// 下载app
	h5appaddressiphone:'https://apps.apple.com/cn/app/id1473535906',
	h5appaddressandroid:'https://sj.qq.com/myapp/detail.htm?apkName=com.saisi.ssjy',

	bol:'', 
	headers:{
		'token':'',
		'version':'v1',
		'fromsource':1,
		'device':'H5'
	}

  },
  mutations:{

  }
}

router.afterEach((to, from) => {
	
})


router.beforeEach((to, from,next) => {
  if (to.path == '/'){
    if (!to.query.scene) {
      // console.log(111)
      //准备一个跳转的query对象
      let query = to.query
      query.scene = '4#wechat_redirect'
      next({
        path: to.path,
        query: query
      })
    } else {
      next()
    }
  }else {
    next();
  }

});


/**
 * 获取当前时间
 * 格式YYYY-MM-DD
 */
Vue.prototype.getNowFormatDate = function() {
  var date = new Date();
  var seperator1 = "/";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate;
};



router.afterEach((to,from,next) => {
  window.scrollTo(0,0);
})


// base64
Vue.filter('base64Decode', function(value) {
  var name = value.replace(/\s+/g, "");
  if ((/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/.test(name))){
		var valuetype = Base64.decode(name);
	}else{
		var valuetype = name;
	}

	return valuetype;
})



Vue.filter('convTime', function(value) {
  let date = new Date(value*1000);
  let y = date.getFullYear();
  let MM = date.getMonth() + 1;
  MM = MM < 10 ? ('0' + MM) : MM;
  let d = date.getDate();
  d = d < 10 ? ('0' + d) : d;
  let h = date.getHours();
  h = h < 10 ? ('0' + h) : h;
  let m = date.getMinutes();
  m = m < 10 ? ('0' + m) : m;
  let s = date.getSeconds();
  s = s < 10 ? ('0' + s) : s;
  return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
})
Vue.filter('convTime1', function(value, type) {
  let date = new Date(value*1000);
  let y = date.getFullYear();
  let MM = date.getMonth() + 1;
  MM = MM < 10 ? ('0' + MM) : MM;
  let d = date.getDate();
  d = d < 10 ? ('0' + d) : d;
  let h = date.getHours();
  h = h < 10 ? ('0' + h) : h;
  let m = date.getMinutes();
  m = m < 10 ? ('0' + m) : m;
  let s = date.getSeconds();
  s = s < 10 ? ('0' + s) : s;
  if (type == "YMD"){
    return MM + '-' + d + ' ' + h + ':' + m
  } else {
    return y + '-' + MM + '-' + d + ' ' + h + ':' + m ;
  }

})
// 解析时间
Vue.filter('data', function (value, type) {
  let dataTime = "";
  let data = new Date();
  data.setTime(value*1000);
  let year = data.getFullYear();
  let month = data.getMonth() + 1;
  let day = data.getDate();
  let hour = data.getHours();
  let minute = data.getMinutes();
  let second = data.getSeconds();
  month < 10 ? (month = "0" + month) : month;
  day < 10 ? (month = "0" + day) : day;
  hour < 10 ? (hour = "0" + hour) : hour;
  minute < 10 ? (minute = "0" + minute) : minute;
  second < 10 ? (second = "0" + second) : second;
  if (type == "YMD") {
    dataTime = year + "." + month + "." + day;
  } else if (type == "YMDHMS") {
    dataTime =
      year +
      "." +
      month +
      "." +
      day +
      "  " +
      hour +
      ":" +
      minute +
      ":" +
      second;
  } else if (type == "HMS") {
    dataTime = hour + ":" + minute + ":" + second;
  } else if (type == "YM") {
    dataTime = year + "-" + month + "-";
  }
  return dataTime; // 将格式化后的字符串输出到前端显示
});

const store = new Vuex.Store(Module);

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
